package io.renren.modules.zhongyi.controller;


import io.renren.common.config.ListPageUtils;
import io.renren.common.utils.R;
import io.renren.modules.zhongyi.service.ZYNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/zy_news")
@Api(tags = "新闻")
public class ZyNewsController {

    @Autowired
    ZYNewsService ZYNewsService;

    @PostMapping("getNewsList")
    @ApiOperation("获取新闻列表")
    public R getNewsList(@RequestBody Map map) {
        int pageSize = (int) map.get("pageSize");
        int pageNum = (int) map.get("pageNum");

        List newsList = ZYNewsService.getNewsList();
        if (newsList != null && newsList.size() > 0) {
            ListPageUtils pageUtils = new ListPageUtils(newsList, pageSize);
            List list = pageUtils.getPagedList(pageNum);
            if (list.size() > 0) {
                return R.ok("根据条件查询新闻成功", 100).put("data", list).put("nextNum", pageNum + 1);
            }
            return R.ok("根据条件查询新闻成功", 100).put("data", list).put("nextNum", pageNum + 1);
        } else {
            return R.ok("暂无数据", 100);
        }
    }
}
